﻿
Namespace std
    Public Class stack(Of valueT, store As backoperatingContainer(Of valueT))
        Implements ICloneable

        Private data As store = Nothing

        Public Sub clear()
            data.clear()
        End Sub

        Public Function empty() As Boolean
            Return data.empty()
        End Function

        Public Function size() As Int64
            Return data.size()
        End Function

#If RETIRED Then
        Public Function front() As valueT
            Return data.front()
        End Function
#End If

        Public Function back() As valueT
            Return data.back()
        End Function

        Public Sub push(ByVal newdata As valueT)
            data.push_back(newdata)
        End Sub

        Public Sub pop()
            data.pop_back()
        End Sub

        Protected Overridable Function generateData() As store
            Return alloc(Of store)()
        End Function

        Public Sub New()
            data = generateData()
        End Sub

        Public Sub New(ByVal that As stack(Of valueT, store))
            copy(data, that.data)
        End Sub

        Public Sub New(ByVal that As store)
            copy(data, that)
        End Sub

        Public Overridable Function Clone() As Object Implements System.ICloneable.Clone
            Return New stack(Of valueT, store)(data)
        End Function
    End Class

    Public Class stack(Of valueT)
        Inherits stack(Of valueT, list(Of valueT))

        'do not really need this, just make the alloc more quickly
        Protected Overrides Function generateData() As list(Of valueT)
            Return New list(Of valueT)()
        End Function

        Public Sub New()
            MyBase.New()
        End Sub

        Public Sub New(ByVal that As stack(Of valueT))
            MyBase.New(that)
        End Sub

        Public Sub New(ByVal that As list(Of valueT))
            MyBase.New(that)
        End Sub

        Public Overrides Function Clone() As Object
            Return New stack(Of valueT)(Me)
        End Function
    End Class
End Namespace
